<?php

/**
 * This is the model class for table "employee".
 *
 * The followings are the available columns in table 'employee':
 * @property integer $id
 * @property string $employee_lname
 * @property string $employee_fname
 * @property string $employee_mname
 * @property integer $employee_telnum
 */
class Employee extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'employee';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('employee_lname, employee_fname, employee_telnum , employee_username, employee_password , employee_usertype', 'required'),
			array('employee_telnum', 'numerical', 'integerOnly'=>true),
			array('employee_lname, employee_fname, employee_mname ,employee_username , employee_usertype', 'length', 'max'=>45),
				array('employee_password ', 'length', 'max'=>255),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, employee_lname, employee_fname, employee_mname, employee_telnum , employee_username, employee_password , employee_usertype', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'tickets' => array(self::HAS_MANY, 'Ticket', 'employee_id'),
			'logs' => array(self::HAS_MANY, 'Logs', 'employee_id'),
		);
	}


	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'employee_lname' => 'Last Name',
			'employee_fname' => 'First Name',
			'employee_mname' => 'Middle Name',
			'employee_telnum' => 'Telephone Number',
			'employee_username' => 'User Name',
			'employee_password' => 'Password',
			'employee_usertype' => 'User Type',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('employee_lname',$this->employee_lname,true);
		$criteria->compare('employee_fname',$this->employee_fname,true);
		$criteria->compare('employee_mname',$this->employee_mname,true);
		$criteria->compare('employee_telnum',$this->employee_telnum);
$criteria->compare('employee_username',$this->employee_username,true);
		$criteria->compare('employee_password',$this->employee_password,true);
		$criteria->compare('employee_usertype',$this->employee_usertype,true);
		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Employee the static model class
	 */

public static function model($className=__CLASS__)
{
return parent::model($className);
}
public function getFullNameEmployee(){
return $this->employee_fname." ".$this->employee_lname;
}
 public function beforeSave(){
 $this->employee_password = hash_hmac('sha256', $this->employee_password,
                Yii::app()->params['encryptionKey']);
                return parent::beforeSave();
      }
}
